﻿
(function () {
    "use strict";

    var nav = WinJS.Navigation;
    var resultListView;

    WinJS.UI.Pages.define("/pages/home/home.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        itemInvoked: function (args) {
            var item = args.detail;
            nav.navigate("/pages/itemdetail/itemdetail.html", { itemID: item.itemPromise._value.data.Id });
        },
        ready: function (element, options) {
            // TODO: Initialize the page here.

            resultListView = document.querySelector('#imageTextList').winControl;
            resultListView.itemDataSource = HomeGroupedList.dataSource;
            resultListView.groupDataSource = HomeGroupedList.groups.dataSource;
            resultListView.oniteminvoked = this.itemInvoked.bind(this);

            //if (WinJS.Application.sessionState.WSTopDataSource != null || WinJS.Application.sessionState.WSTopDataSource != undefined)
            //    resultListView.itemDataSource = WinJS.Application.sessionState.WSTopDataSource.dataSource;
            //else
            //    loadTopDownloads();
        }
    });

    function progressSearch(onoff) {
        var divprogress = document.getElementById('searchProgress');

        if (divprogress.hasChildNodes()) {
            while (divprogress.firstChild) divprogress.removeChild(divprogress.firstChild);
        }

        if (onoff) {
            divprogress.appendChild(document.createElement("progress"));
            var eleprogress = divprogress.querySelector("progress");
            WinJS.Utilities.addClass(eleprogress, "win-large");
        }
    }

})();

function groupTitleMouseOver(element) {
    element.setAttribute('class', 'groupTitleOver');
}

function groupTitleMouseOut(element) {
    element.setAttribute('class', 'groupTitle');
}
